﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Xml.Linq;

namespace XBD.MyBaseCode
{
    internal class Signal
    {
        public static ManualResetEvent manualResetEvent = new ManualResetEvent(false);
        public static void ManualResetEventDemo() 
        {
             
            Console.WriteLine("\n start 3 named threads that block on a ManualResetEvent \n");
            for (int i = 0; i <= 2; i++) 
            {
                Thread t = new Thread(ThreadProc);
                t.Name = "Thread_" + i;
                t.Start();
            }
            Thread.Sleep(5000);
            Console.WriteLine("\n when all three threads have started, press Enter to call Set()");
            Console.ReadLine();
            manualResetEvent.Set();
            Thread.Sleep(5000);
            Console.WriteLine("\n when a ManualResetEvent  is signaled ,threads that call Waitone()");
            Console.ReadLine();

        }

        /**
         * 
         */
        public static void ThreadProc() 
        {
            string name = Thread.CurrentThread.Name;

            Console.WriteLine(name + "starts and calls ");

            manualResetEvent.WaitOne();

            Console.WriteLine(manualResetEvent.WaitOne());

            Console.WriteLine(name + "ends");
        }
    }
}
